class Solution {
public:
    int lengthLongestPath(string input) {
        unordered_map<int,int> hash;
        hash[0] = 0;
        
        int len = 1;
        int Max = 0;
        int i = -1;
        int j = 0;
        bool flag = false;
        
        for(;j < input.size();j++){
            if(input[j] == '.'){
                flag = true;
            }
            if(input[j] == '\t'){
                len++;
                i = j;
            }
            if(input[j] == '\n'){
                int k = j - i;
                i = j;
                hash[len] = k + hash[len-1];
                if(flag){
                    Max = max(hash[len],Max);
                    flag = false;
                }
                len = 1;
            }
        }
        if(flag){
            int k = j - i;
            hash[len] = k + hash[len-1];
            Max = max(hash[len],Max);
        }
        if(!flag){
            Max = 0;
        }
        return Max == 0 ? 0 : Max - 1;
    }
};
